package com.gz.test1;

import org.junit.jupiter.api.Test;

import java.util.*;

public class template {
    public static void main(String[] args) {
        //<?>支持任意泛型类型
        //<?> extend A :A及其子类
        //<?> super A :A及其父类
    }

    @Test
    public void testlist(){
        DAO<User> dao = new DAO<>();
        dao.save("1",new User("gz",210049,22));
        dao.save("2",new User("jyx",210048,21));
        dao.save("3",new User("hf",210047,22));
        dao.save("4",new User("lx",2100410,21));
        dao.save("5",new User("mjy",2100411,22));
        List<User> users = dao.list();
        System.out.println("users "+users);
    }
}


class DAO<T>{

    private Map <String,T>map = new HashMap<>();

    public void save(String id, T entity){
        map.put(id,entity);
    }

    public T get(String id){
        return map.get(id);
    }

    public void update(String id, T entity){
        map.put(id,entity);
    }

    public List<T> list(){
        ArrayList<T> arrayList = new ArrayList<>();
        for(Object value : map.values()){
            arrayList.add((T)value);
        }

/*        Set<String> strings = map.keySet();
        for (String string : strings) {
            arrayList.add(map.get(string));
        }*/
        return arrayList;
    }

    public void delete(String id){
        map.remove(id);
    }
}


class User{
    private String name;
    private int age;
    private int id;

    public User(String name, int id, int age) {
        this.name = name;
        this.age = age;
        this.id = id;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    @Override
    public String toString() {
        return "User{" +
                "name='" + name + '\'' +
                ", age=" + age +
                ", id=" + id +
                '}';
    }
}